//
//  SMHHomeHeadView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/1/9.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import SwiftyFitsize
import Kingfisher

class SMHHomeHeadView: UICollectionReusableView {

    @objc var viewModel = SMHHomeViewModel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI()  {
        
        //MARK : head
        let imageView = UIImageView(image: UIImage.init(named: "icon_home_barner"))
        imageView.backgroundColor = UIColor.red
        self.addSubview(imageView)
        imageView.snp.makeConstraints({ (make) in
            make.top.left.right.equalTo(0)
            make.height.equalTo(200)
        })
            
       
        //速卖货
        let appName = UILabel()
        appName.backgroundColor = UIColor.white
        appName.textAlignment = .center
        appName.text = "速卖货"
        appName.font = ktextFont(size: 11)
        appName.textColor = UIColorFromHex(rgbValue: 0xFF661B);
        imageView.addSubview(appName)
        appName.snp.makeConstraints({ (make) in
            make.left.equalTo(28)
            make.top.equalTo(28)
            make.width.equalTo(60)
            make.height.equalTo(18)
        })
        
        appName.layoutIfNeeded()
        
        let maskPath = UIBezierPath(roundedRect: appName.bounds, byRoundingCorners: [.bottomLeft, .bottomRight, .topRight], cornerRadii: CGSize(width: 9, height: 9))
        let maskLayer = CAShapeLayer()
        //设置大小
        maskLayer.frame = appName.bounds
        //设置圆形样子
        maskLayer.path = maskPath.cgPath
        appName.layer.mask = maskLayer
        
        
        ///全年里面
        let profitLab = UILabel()
        profitLab.text = "全年中间利润(元)"
        profitLab.textColor = UIColor.white
        profitLab.font = ktextFont(size: 15~)
        imageView.addSubview(profitLab)
        profitLab.snp.makeConstraints { (make) in
            make.left.equalTo(28)
            make.top.equalTo(appName.snp.bottom).offset(9)
            make.right.equalTo(-10)
            make.height.equalTo(15)
        }
        
        
        //金额
        let numberView = SMHProfitNumberView.init(viewModel: self.viewModel)
        numberView.backgroundColor = UIColor.orange
        imageView.addSubview(numberView)
        numberView.snp.makeConstraints { (make) in
            make.left.equalTo(28)
            make.top.equalTo(profitLab.snp.bottom).offset(9)
            make.right.equalTo(-95)
            make.height.equalTo(30)
        }
        
        //提示
        let tipLab = UILabel()
        tipLab.font = ktextFont(size: 11)
        tipLab.textColor = UIColor.white
        tipLab.text = "日常消费即可瓜分  平台赋予智慧\n数据驱动零售  简单分享  创业即可成功"
        let tipAttributedString = NSMutableAttributedString(string: tipLab.text ?? "")
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 5
        let paragraphStyleDict = [NSAttributedString.Key.paragraphStyle: paragraphStyle]
        tipAttributedString.addAttributes(paragraphStyleDict, range: NSMakeRange(0, tipLab.text?.count ?? 0))
        tipLab.numberOfLines = 0
        tipLab.attributedText = tipAttributedString
        imageView.addSubview(tipLab)
        tipLab.snp.makeConstraints { (make) in
            make.left.equalTo(28)
            make.bottom.equalTo(-42)
            make.right.equalTo(-10)
            make.height.equalTo(38)
        }

        
        let activityBtn = UIButton()
        activityBtn.backgroundColor = UIColor.orange
        self.addSubview(activityBtn)
        activityBtn.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.top.equalTo(imageView.snp.bottom).offset(5)
            make.height.equalTo(110)
        }
        activityBtn.kf.setImage(with: URL(string: "http://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/267f9e2f07082838685c484ab999a9014c08f11f.jpg"), for: .normal)
    }
    
}
